package com.huike.clues.service.impl;


import com.github.pagehelper.Page;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 新增线索跟进记录
     *
     * @param tbClueTrackRecord
     */
    @Override
    public void addTrackRecord(ClueTrackRecordVo tbClueTrackRecord) {
        //修改线索表中信息
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord, tbClue);//将tbClueTrackRecord中的数据赋值给tbClue(名称相同)
        tbClue.setId(tbClueTrackRecord.getClueId());//设置id
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());//修改状态
        tbClueMapper.updateTbClue(tbClue);
        //添加线索跟踪信息
        TbClueTrackRecord tbClueTrackRecord1 = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord, tbClueTrackRecord1);
        tbClueTrackRecord1.setCreateTime(new Date());
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecordMapper.add(tbClueTrackRecord1);
    }

    /**
     * 查询线索跟进记录列表
     *
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecordById(Long clueId) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordById(clueId);

    }


}
